<template>
  <el-dialog title="上传资料" :visible.sync="dialogVisible" width="30%" :append-to-body="true">
    <el-form ref="editForm" :model="form" :rules="rules" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="公司名称">{{form.org_name}}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目名称">{{form.project_name}}</el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系人">{{form.link_man}}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话">{{form.link_phone}}</el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="保函类型">{{form.type}}</el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="保函额度">{{form.money}}万元</el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="代办费用" >
        <el-input v-model="form.cp_money" type="number"></el-input>
      </el-form-item>
      <el-form-item label="尾款" >
        <el-input v-model="form.backletter_money" type="number"></el-input>
      </el-form-item>
      <el-form-item label="线下信息提交">
        <el-switch v-model="form.info_upload" active-value="已提交" inactive-value="未提交"></el-switch>
      </el-form-item>
      <el-form-item label="状态" prop="statuz">
        <el-select v-model="form.statuz" style="width:100%">
          <el-option v-for="item in data" :key="item" :label="item" :value="item"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit('editForm')">保存</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
import { baseUrl } from "@/config/env";
const urls = {
  get: baseUrl + "/zweixin/fk/bl/get",
  save: baseUrl + "/zweixin/fk/bl/edit"
};
export default {
  data() {
    return {
      dialogVisible: false,
      data: ["申请中", "申请成功", "办理中", "办理完成", "已取消"],
      form: {
        kid: null,
        org_name: null,
        project_name: null,
        link_man: null,
        link_phone: null,
        type: null,
        money: null,
        cp_money: 0,
        backletter_money: 0,
        info_upload: null,
        statuz: null
      },
      rules: {
        cp_money: [
          {  message: "请填写代办费用", trigger: "blur" }
        ],
        backletter_money: [
          {  message: "请填写尾款", trigger: "blur" }
        ],
        statuz: [{ required: true, message: "请选择保函状态", trigger: "blur" }]
      }
    };
  },
  components: {},
  methods: {
    show(kid) {
      this.dialogVisible = true;
      if (this.$refs["editForm"]) {
        this.$refs["editForm"].resetFields();
      }
      this.fetch(kid);
    },
    onSubmit(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          axios.post(urls.save, this.form).then(res => {
            this.$message(res.data.result);
            this.dialogVisible = false;
            this.$emit("refresh");
          });
        }
        return false;
      });
    },
    fetch(kid) {
      axios.get(urls.get, { params: { kid: kid } }).then(res => {
        let data = res.data.result;
        this.form = {
          kid: data.kid,
          org_name: data.org_name,
          project_name: data.project_name,
          link_man: data.link_man,
          link_phone: data.link_phone,
          type: data.type,
          money: data.money,
          cp_money: data.cp_money,
          backletter_money: data.backletter_money,
          info_upload: data.info_upload,
          statuz: data.statuz
        };
      });
    }
  }
};
</script>